package com.cloudwebrtc.preference;

import com.cloudwebrtc.util.Contacts;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;

public class SettingSharedPreference {

	private static SettingSharedPreference instance;
	
	private SharedPreferences  sp;
	
	private SettingSharedPreference(){
		
		
	}
	
	public static SettingSharedPreference getSharedPreferenceUtils(){
		if(instance == null)
			instance = new SettingSharedPreference();
		return instance;
	}
	
	/**
	 *  保存数据
	 * @param context
	 * @param key
	 * @param defValue
	 * @return
	 */ 
	public void saveDate(Context context,String key,String value){
		
		if(sp == null)
		   sp = context.getSharedPreferences(Contacts.BEECHAT_SETTIONG,Context.MODE_WORLD_WRITEABLE);  
		Editor editor = sp.edit();  
		editor.putString(key, value);  
		editor.commit();
	}
	
	/**
	 *  保存数据
	 * @param context
	 * @param key
	 * @param defValue
	 * @return
	 */ 
	public void saveDate(Context context,String key,boolean value){
		
		if(sp == null)
			 sp = context.getSharedPreferences(Contacts.BEECHAT_SETTIONG,Context.MODE_WORLD_WRITEABLE);  
	    Editor editor = sp.edit();    
		editor.putBoolean(key, value);  
		editor.commit();
	} 
	
	/**
	 *  取出数据
	 * @param context
	 * @param key
	 * @param defValue
	 * @return
	 */
	public String getDate(Context context,String key,String defValue){
		
		if(sp == null)
			 sp = context.getSharedPreferences(Contacts.BEECHAT_SETTIONG,Context.MODE_WORLD_WRITEABLE);  
		return sp.getString(key, defValue);
	}
	/**
	 *  取出数据
	 * @param context
	 * @param key
	 * @param defValue
	 * @return
	 */
	public boolean getDate(Context context,String key,boolean defValue){
		
		if(sp == null)
			sp = context.getSharedPreferences(Contacts.BEECHAT_SETTIONG,Context.MODE_WORLD_WRITEABLE);  
		return sp.getBoolean(key, defValue);
	}
	
}
